<template>
  <div>
    <div style="float: right;margin-right:2%;">
      <div style="position: relative;display: inline-block;">
        <span>省/直辖市名称：</span>
        <el-input style="width: 200px;" @keydown.enter.native="sxNotice" placeholder="请输入省/直辖市名称" v-model="cityNameT">
        </el-input>&nbsp;&nbsp;
      </div>
      <el-button style='margin: 10px 0;' size="mini" type="primary" icon="document" @click="sxNotice">刷新</el-button>
      <!-- <el-button style='margin: 10px 0;' :disabled="!isAuth('IntegralGoods:add')" size="mini" type="primary"
        icon="document" @click="addNotice">添加</el-button> -->
    </div>

    <el-table v-loading="tableDataLoading" :data="tableData.records" row-key='id'>
      <el-table-column fixed prop="id" label="编号" width="80">
      </el-table-column>
      <el-table-column prop="username" label="代理商昵称" fixed>
      </el-table-column>
      <el-table-column prop="mobile" label="代理商手机号">
      </el-table-column>
      <el-table-column prop="cityName" label="城市名称" fixed>
      </el-table-column>
      <el-table-column prop="baseKilometres" label="基础公里数">
      </el-table-column>
      <el-table-column prop="baseMoney" label="基础价格">
      </el-table-column>
      <el-table-column prop="unitOverMoney" label="额外每公里价格(单位:元)">
      </el-table-column>
      <el-table-column prop="nightMoney" label="每公里费用(22:00~23:59)">
      </el-table-column>
      <el-table-column prop="earlyMoney" label="每公里费用(00:00~06:59)">
      </el-table-column>
      <el-table-column prop="minuteMoney" label="每分钟时长费(单位:元)">
      </el-table-column>
      <el-table-column prop="pingRate" label="平台抽成比例(0.1表示10%)">
      </el-table-column>
      <el-table-column prop="riderRate" label="师傅收益默认比例(0.1表示10%)">
      </el-table-column>
      <!-- <el-table-column prop="isCover" label="是否修改代理城市下所有骑手的分佣比例">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.isCover" @change="change1(scope.row.isCover,scope.row)"
            :active-value="openValue" :inactive-value="closeValue" active-color="#13ce66" inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column> -->
      <el-table-column prop="waitMinuteMoney" label="等待每分钟价格">
      </el-table-column>
      <el-table-column prop="freeWaitTime" label="免费等待时长(分钟)">
      </el-table-column>
      <el-table-column prop="agentTime" label="修改时间">
      </el-table-column>
      <el-table-column prop="sort" label="排序">
      </el-table-column>
      <el-table-column prop="isEnable" label="是否启用" fixed="right">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.isEnable" @change="change2(scope.row.isEnable,scope.row)"
            :active-value="openValue" :inactive-value="closeValue" active-color="#13ce66" inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column>
    <el-table-column label="操作" width="100"fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" :disabled="!isAuth('IntegralGoods:update')" style="margin: 3px;"
            @click="amendBanner(scope.row)">修改
          </el-button>
          <el-button size="mini" type="danger" :disabled="!isAuth('IntegralGoods:delete')" style="margin: 3px;"
            @click="deletes(scope.row)">取消代理
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="text-align: center;margin-top: 10px;">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :page-sizes="[5, 10, 20, 30, 50, 100]" :page-size="limit" :current-page="page"
        layout="total,sizes, prev, pager, next,jumper" :total="tableData.total">
      </el-pagination>
    </div>
    <el-dialog :title="title" :visible.sync="dialogFormVisible" center>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">基础公里数：</span>
        <el-input style="width:50%;" v-model="baseKilometres" placeholder="请输入基础公里数"></el-input>
      </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">基础价格：</span>
        <el-input style="width:50%;" v-model="baseMoney" placeholder="请输入基础价格"></el-input>
      </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">额外每公里价格(单位:元)：</span>
        <el-input style="width:50%;" v-model="unitOverMoney" placeholder="请输入额外每公里价格(单位:元)"></el-input>
      </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">每公里费用(22:00~23:59)：</span>
        <el-input style="width:50%;" v-model="nightMoney" placeholder="请输入每公里费用(22:00~23:59)"></el-input>
      </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">每公里费用(00:00~06:59)：</span>
        <el-input style="width:50%;" v-model="earlyMoney" placeholder="请输入每公里费用(00:00~06:59)"></el-input>
      </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">每分钟时长费(单位:元)：</span>
        <el-input style="width:50%;" v-model="minuteMoney" placeholder="请输入每分钟时长费(单位:元)"></el-input>
      </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">平台抽成比例(0.1表示10%)：</span>
        <el-input style="width:50%;" v-model="pingRate" disabled placeholder="请输入平台抽成比例(0.1表示10%)"></el-input>
      </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">师傅收益默认比例(0.1表示10%)：</span>
        <el-input style="width:50%;" v-model="riderRate" placeholder="请输入师傅收益默认比例(0.1表示10%)"></el-input>
      </div>
     <div style="margin-bottom: 10px;">
       <span style="width: 300px;display: inline-block;text-align: right;">同步师傅分佣比例：</span>
     				<el-radio-group v-model="isCover">
     				  
     				  <el-radio :label="1">是</el-radio>
     					<el-radio :label="0">否</el-radio>
     				</el-radio-group>
       <!-- <el-input style="width:50%;" v-model="isCover" placeholder="请输入是否修改代理城市下所有骑手的分佣比例"></el-input> -->
     </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">等待每分钟价格：</span>
        <el-input style="width:50%;" v-model="waitMinuteMoney" placeholder="请输入等待每分钟价格"></el-input>
      </div>
      <div style="margin-bottom: 10px;">
        <span style="width: 300px;display: inline-block;text-align: right;">免费等待时长(分钟)：</span>
        <el-input style="width:50%;" v-model="freeWaitTime" placeholder="请输入免费等待时长(分钟)"></el-input>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addNoticeTo()">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        page: 1,
        limit: 10,
        size1: 10,
        page1: 1,
        tableDataLoading: true,
        dialogFormVisible: false,
        tableData: {},
        redPacketMoney: '',
        memberImg: '',
        isEnable: 1,
        money: '',
        redPacketNum: '',
        id: '',
        title: '添加',
        openValue: 2,
        closeValue: 1,
        tableDataY: {},
        price: '',
        memberId: '',
        cityName: '',
        couponId: '',
        couponName: '',
        sort: '',
        payClassifyId: '',
        dialogFormVisible4: false,
        radio: 0,
        provinceId: '',
        cityId: '',
        provinceList: [],
        cityList: [],
        parentId: 0,
        cityNameT: '',
        agentUserId:'',
        baseKilometres: 5, //基础公里数
        baseMoney: 20, //基础价格
        unitOverMoney: 3, //额外每公里价格(单位:元)
        nightMoney: 1, //每公里费用（22:00~23:59）
        earlyMoney: 0.5, //每公里费用（00:00~06:59）
        minuteMoney: 0.5, //每分钟时长费(单位:元)
        pingRate: 0.2, //平台抽成比例（0.1表示10%）
        riderRate: 0.5, //师傅收益默认比例（0.1表示10%）
        isCover: 0, //同步师傅分佣比例 0否 1是
        waitMinuteMoney:'',// 等待每分钟价格
        freeWaitTime:'',// 免费等待时长(分钟)
      }
    },
    methods: {
      // 获取数据列表
      dataSelect() {
        this.tableDataLoading = true
        this.$http({
          url: this.$http.adornUrl('admin/cityInfo/getHasAgentCityList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.page,
            'limit': this.limit,
            // 'parentId': 0,
            'cityName': this.cityNameT,
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            console.log('会员列表', data)
            this.tableDataLoading = false
            let returnData = data.data;
            this.tableData = returnData;
            console.log(this.tableData,'-----------------')
            // if (this.tableData.records.length == 0) {
            //   if (this.page > 1) {
            //     this.page = this.page - 1
            //     this.dataSelect()
            //   }
            // }
          }

        })
      },
      //上传成功
      handleAvatarSuccess(file) {
        this.memberImg = file.data
      },
      // 刷新
      sxNotice() {
        this.page = 1
        this.dataSelect()
      },
      addNotice() {

        this.agentUserId = ''
        this.baseKilometres = ''
       this.baseMoney = ''
       this.unitOverMoney = ''
       this.nightMoney = ''
       this.earlyMoney = ''
       this.minuteMoney = ''
       this.pingRate = ''
       this.riderRate = ''
       this.waitMinuteMoney = ''
       this.freeWaitTime = ''
       this.id = ''
       this.isCover = 0
        this.title = '添加'
        this.dialogFormVisible = true
      },
      handleCurrentChange(val) {
        this.page = val
        this.dataSelect()
      },
      handleSizeChange(val) {
        this.limit = val
        this.dataSelect()
      },

      // 是否启用
      change2(val, row) {
        this.$http({
          url: this.$http.adornUrl('admin/cityInfo/updateEnable'),
          method: 'get',
          params: this.$http.adornParams({
            // data: this.$http.adornData({
            'id': row.id,
          })
        }).then(({
          data
        }) => {
          if (data.code == 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.dataSelect()
              }
            })
          } else {
            this.$message({
              message: data.msg,
              type: 'warning',
              duration: 1500,
              onClose: () => {
                this.dataSelect()
              }
            })
          }
        })
      },
      // 是否启用
      change1(val, row) {
        return
        this.$http({
          url: this.$http.adornUrl('admin/cityInfo/updateEnable'),
          method: 'get',
          params: this.$http.adornParams({
            // data: this.$http.adornData({
            'id': row.id,
          })
        }).then(({
          data
        }) => {
          if (data.code == 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.dataSelect()
              }
            })
          } else {
            this.$message({
              message: data.msg,
              type: 'warning',
              duration: 1500,
              onClose: () => {
                this.dataSelect()
              }
            })
          }
        })
      },
      // 修改
      amendBanner(rows) {
        this.agentUserId = rows.agentUserId
        this.baseKilometres = rows.baseKilometres
        this.baseMoney = rows.baseMoney
        this.unitOverMoney = rows.unitOverMoney
        this.nightMoney = rows.nightMoney
        this.earlyMoney = rows.earlyMoney
        this.minuteMoney = rows.minuteMoney
        this.pingRate = rows.pingRate
        this.riderRate = rows.riderRate
        this.isCover = rows.isCover
        this.id = rows.id
        this.waitMinuteMoney = rows.waitMinuteMoney
        this.freeWaitTime = rows.freeWaitTime
        this.title = '修改'
        this.dialogFormVisible = true
      },
      // 确认修改
      addNoticeTo() {
        // if (this.title == '添加') {
        //   if (this.radio == 1) {
        //     if (this.provinceId === '') {
        //       this.$notify({
        //         title: '提示',
        //         duration: 1800,
        //         message: '请选择省/直辖市',
        //         type: 'warning'
        //       });
        //       return
        //     }
        //     this.parentId = this.provinceId

        //   }
        //   if (this.radio == 2) {
        //     if (this.provinceId === '') {
        //       this.$notify({
        //         title: '提示',
        //         duration: 1800,
        //         message: '请选择省/直辖市',
        //         type: 'warning'
        //       });
        //       return
        //     }
        //     if (this.cityId === '') {
        //       this.$notify({
        //         title: '提示',
        //         duration: 1800,
        //         message: '请选择城市',
        //         type: 'warning'
        //       });
        //       return
        //     }
        //     this.parentId = this.cityId
        //   }
        // }

        // if (this.cityName == '') {
        //   this.$notify({
        //     title: '提示',
        //     duration: 1800,
        //     message: '请输入名称',
        //     type: 'warning'
        //   });
        //   return
        // }
        if (this.title == '添加') {
          var url = 'admin/cityInfo/updateCityRate'
        } else {
          var url = 'admin/cityInfo/updateCityRate'
        }
        this.$http({
          url: this.$http.adornUrl(url),
          method: 'post',
          params: this.$http.adornParams({
          // data: this.$http.adornData({
            'agentUserId': this.agentUserId,
            'baseKilometres': this.baseKilometres,
            'baseMoney': this.baseMoney,
            'unitOverMoney': this.unitOverMoney,
            'nightMoney': this.nightMoney,
            'earlyMoney': this.earlyMoney,
            'minuteMoney': this.minuteMoney,
            'pingRate': this.pingRate,
            'riderRate': this.riderRate,
            'isCover': this.isCover,
            'id':this.id,
            'waitMinuteMoney': this.waitMinuteMoney,
            'freeWaitTime': this.freeWaitTime,

          }, false, 'from')
        }).then(({
          data
        }) => {
          if (data.code == 0) {
            this.dialogFormVisible = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {

                this.dataSelect()
              }
            })
          } else {
            this.$message({
              message: data.msg,
              type: 'warning',
              duration: 1500,
              onClose: () => {}
            })
          }

        })
      },
      //取消代理
      deletes(row) {
        let delid = row.id
        this.$confirm(`确定要取消该城市的代理?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: ''
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('admin/cityInfo/setAgentCity'),
            method: 'get',
            params: this.$http.adornParams({
              'id': delid,
              'userId':''
            })
          }).then(({
            data
          }) => {
            if (data.code == 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.dataSelect()
                }
              })
            } else {
              this.$message({
                message: data.msg,
                type: 'warning',
                duration: 1500,
                onClose: () => {}
              })
            }

          })
        }).catch(() => {})
      },
    },
    mounted() {
      this.dataSelect()
    }
  }
</script>

<style>
</style>
